<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="!crud.props.searchToggle">
        <el-form size="small" label-width="70px">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <rrOperation :crud="crud"/>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="来源类型">
            <el-input v-model="form.sourceType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="来源单据号">
            <el-input v-model="form.sourceCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="操作类型">
            <el-input v-model="form.operType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="初始数量">
            <el-input v-model="form.initNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="增加数量">
            <el-input v-model="form.inNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="减少数量">
            <el-input v-model="form.outNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="最终数量">
            <el-input v-model="form.endNum" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加人">
            <el-input v-model="form.createUserName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="添加时间">
            <el-input v-model="form.createTime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" stripe border v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler" :cell-style="{'text-align':'center'}">
<!--        <el-table-column type="selection" width="55" />-->
        <el-table-column type="index" width="55" label="序号"/>
<!--        <el-table-column v-if="columns.visible('id')" prop="id" label="id" />-->
        <el-table-column v-if="columns.visible('sourceType')" prop="sourceType" label="来源类型" width="150"/>
        <el-table-column v-if="columns.visible('sourceCode')" prop="sourceCode" label="来源单据号" width="120"/>
        <el-table-column v-if="columns.visible('operType')" prop="operType" label="操作类型" />
        <el-table-column v-if="columns.visible('initNum')" prop="initNum" label="初始数量" />
        <el-table-column v-if="columns.visible('inNum')" prop="inNum" label="增加数量" />
        <el-table-column v-if="columns.visible('outNum')" prop="outNum" label="减少数量" />
        <el-table-column v-if="columns.visible('endNum')" prop="endNum" label="最终数量" />
        <el-table-column v-if="columns.visible('remark')" prop="remark" label="备注" />
        <el-table-column v-if="columns.visible('createUserName')" prop="createUserName" label="添加人" />
        <el-table-column v-if="columns.visible('createTime')" prop="createTime" label="添加时间" width="150">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime) }}</span>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudPlasticDepositDetail from '@/api/erp/plasticDepositDetail'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({
  title: '塑箱押金记录明细',
  url: 'api/plasticDepositDetail',
  sort: 'id,desc',
  params() {
    const href = location.href.split('/')
    return {
      orderId: href[href.length - 1] == 'add' ? 0 : href[href.length - 1], page: 0, size: 999,
    }
  },
  crudMethod: { ...crudPlasticDepositDetail }
})
const defaultForm = { id: null, orderId: null, sourceType: null, sourceId: null, sourceCode: null, sourceDetailId: null, operType: null, initNum: null, inNum: null, outNum: null, endNum: null, remark: null, createUserId: null, createTime: null }
export default {
  name: 'PlasticDepositDetail',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {

      permission: {
        add: ['admin', 'plasticDepositDetail:add'],
        edit: ['admin', 'plasticDepositDetail:edit'],
        del: ['admin', 'plasticDepositDetail:del'],
        import: ['admin', 'plasticDepositDetail:import'],
        export: ['admin', 'plasticDepositDetail:export'],
        copy: ['admin', 'plasticDepositDetail:copy'],
        upload: ['admin', 'plasticDepositDetail:upload'],
        download: ['admin', 'plasticDepositDetail:download'],
      },
      rules: {
        orderId: [
          { required: true, message: '塑箱押金id不能为空', trigger: 'blur' }
        ]
      }    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },

  }
}
</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
